/**
 * Created by feimao on 15-12-8.
 */
$.getJSON('../recipeData/json/cn_ziranyangrou_data.json', function (obj) {
    var name = "孜然羊肉片";
    showTitle(obj[name]);
    showHeader(obj[name]);
    showIntroduction(obj[name]);
    showFoodList(obj[name]);
    showMakeList(obj[name]);
    if (obj[name].tips[0]) showTips(obj[name]);
});

function showTitle(menu) {
    $("title").text(menu.name + '的做法')
}

function showHeader(menu) {
    $(".img").css("background-image", "url(" + menu.img_url + ")");
    $(".menu-name").text(menu.name);
    //$(".introduction").text(menu.introduction);
}

function showIntroduction(menu) {
    menu.introduction.forEach(function (value) {
        $(".introduction").append(value + "<br>")
    });
}

function showFoodList(menu) {
    menu.food_lists.forEach(function (list) {
        $(".food-list").append("<h2>" + list.list_name + "</h2><ul id=" + list.list_name + "></ul>");
        getFood(list);
    });
    function getFood(list) {
        list.food.forEach(function (value) {
            $("#" + list.list_name).append("<li><span class='food-name'>" + value.food_name + "</span>" +
                "<span class='food-note'>" + value.food_note + "</span></li>");
        });
    }
}

function showMakeList(menu) {
    menu.make_lists.forEach(function (list) {
        $(".make-list").append("<h2>" + list.list_name + "</h2><ul id=" + list.list_name + "></ul>");
        getMeans(list);
    });
    function getMeans(list) {
        list.make.forEach(function (value, index) {
            if (value.make_img) {
                $("#" + list.list_name).append("<li><aside style='float: left'>" + (index + 1) + "</aside>" +
                    "<div style='overflow: hidden'><img src=" + value.make_img + "><p>" + value.make_text + "</p></div></li>");
            }
            else {
                $("#" + list.list_name).append("<li><aside style='float: left'>" + (index + 1) + "</aside>" +
                    "<div style='overflow: hidden'><p>" + value.make_text + "</p></div></li>");
            }
        });
    }
}

function showTips(menu) {
    $(".tips").append("<h3>小贴士</h3><p></p>");
    menu.tips.forEach(function (value, index) {
        $(".tips p").append(value + "<br>");
    });
}
